import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;


import javax.swing.BoxLayout;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import java.util.ListIterator;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import java.util.Date;

import calendar_ex.*;
import calendar_ex.Appointment.Recurrence;
import javax.swing.Box;
import javax.swing.Box.Filler;
import javax.swing.table.DefaultTableModel;

import panels.Inner;
import panels.SwipeButtons;

import views.*;
import functions.*;

//import calendar_ex.*;
//import teamcalendar.*;


public class NewCalendar extends JFrame implements ActionListener, WindowListener{
	
//	CalendarEx cal;
	int screenWidth = 240;
	int screenHeight = 320;
	int screenSizeMult = 2;
	
	JPanel cards;
	
	public NewCalendar(){
		//JPanel startPanel = new MainPanel();
	}
	
	public void createAndShowGUI(){
		setMinimumSize(new Dimension(screenWidth*screenSizeMult, screenHeight*screenSizeMult));
		setVisible(true);
		setTitle("New Calendar");
		
		//getContentPane().setLayout(new CardLayout());
		
		ControlActionListenter calistener = new ControlActionListenter();
		
		JPanel topPane = new JPanel();
		
		Button dayViewBttn = new Button("Day");
		dayViewBttn.setActionCommand("DAY_VIEW");
		dayViewBttn.addActionListener(calistener);
		topPane.add(dayViewBttn, "DAY_VIEW");
		
		Button weekViewBttn = new Button("Week");
		weekViewBttn.setActionCommand("WEEK_VIEW");
		weekViewBttn.addActionListener(calistener);
		topPane.add(weekViewBttn, "WEEK_VIEW");
		
		Button monthViewBttn = new Button("Month");
		monthViewBttn.setActionCommand("MONTH_VIEW");
		monthViewBttn.addActionListener(calistener);
		topPane.add(monthViewBttn, "MONTH_VIEW");
		
		JPanel dayView = new JPanel();
		String dayViewText = "Day View";
		dayView.add(new JLabel(dayViewText));
		DefaultTableModel dataModel = new DefaultTableModel();
		String[] headers = {"Hour" ,"Schedule"}; //All headers
		Object[] rowData = new Object[24];
		for (int i=0; i<2; i++)
			dataModel.addColumn(headers[i]);
		for(int i=0; i<24; i++){
            JButton but = new JButton(" "+i);
			rowData[0]= but;
			dataModel.addRow(rowData);
		}

		JTable table = new JTable(dataModel);
		table.setRowHeight(30);
		
		table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		JScrollPane wvPanel = new JScrollPane(table);
		wvPanel.setPreferredSize(new Dimension(355,520));
		dayView.add(wvPanel);
		
		JPanel weekView = new JPanel();
		String weekViewText = "Week View";
		weekView.add(new JLabel(weekViewText));
		
		
		
		JPanel monthView = new JPanel();
		String monthViewText = "Month View";
		monthView.add(new JLabel(monthViewText));
		
		
		
		
		cards = new JPanel(new CardLayout());
		cards.add(dayView, "DAY_VIEW");
		cards.add(weekView, "WEEK_VIEW");
		cards.add(monthView, "MONTH_VIEW");
		
		topPane.setVisible(true);
		topPane.setBackground(new Color(93,138, 168));
		getContentPane().add(topPane, BorderLayout.PAGE_START);
		getContentPane().add(cards, BorderLayout.CENTER);
	}
	
	class ControlActionListenter implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            CardLayout cl = (CardLayout) (cards.getLayout());
            String cmd = e.getActionCommand();
            if (cmd.equals("DAY_VIEW")) {
                cl.show(cards, "DAY_VIEW");
            }else if (cmd.equals("WEEK_VIEW")){
            	cl.show(cards, "WEEK_VIEW");
            }else if (cmd.equals("MONTH_VIEW")){
            	cl.show(cards, "MONTH_VIEW");
            }
        }
    }
    
	
	public static void main(String[] args){
		
		NewCalendar cal = new NewCalendar();
        cal.createAndShowGUI();
        /*
		javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
            	NewCalendar cal = new NewCalendar();
                cal.createAndShowGUI();
            }
        });*/
	}
	
	public class MainPanel extends JPanel{
		public MainPanel(){
			
		}
	}

	@Override
	public void windowOpened(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowClosing(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowClosed(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowIconified(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowDeiconified(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowActivated(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowDeactivated(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		
	}

	
	
}